-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spree::OptionValue#name delegates to Spree::OptionType even when nil #3517
Spree::OptionValue#name delegates to Spree::OptionType even when nil #3517
Conversation
…ame to it Spree::OptionValue#name is delegated to Spree::OptionType with option_type prefix (option_type_name). https://github.com/solidusio/solidus/blob/v2.9.5/core/app/models/spree/option_value.rb#L17 The json response of Spree::Api::OptionValuesController uses the *option_value_attributes helper variable which has :option_type_name. If for some reason an option value is created without option_type the above controller will return a 500 error because the name delegation. This commit also remove check_option_values from the option_values_controller_spec.rb because is not used anywhere in the file.
The above line already configures all the routes for the option value resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SamuelMartini thanks for catching this!
I am in favor of this change, I just wonder if we should allow creating option values without option type 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SamuelMartini thanks. I'm ok with the change and I also can't see a scenario where someone could need an option value without an option type but this is reflected in model validations and it seems to be legit.
It makes no sense to have dangling option_values without an associated option_type. Ref solidusio#3309 & solidusio#3517
@SamuelMartini I know this is quite old, but any chance you remember why you needed to create an option value without an option type? |
It makes no sense to have dangling option_values without an associated option_type. Ref solidusio#3309 & solidusio#3517
Description
Spree::OptionValue#name is delegated to
Spree::OptionType
withoption_type
prefix (option_type_name).The json response of
Spree::Api::OptionValuesController
uses the*option_value_attributes
helper variable which includes :option_type_name.If for some reason an option value is created without option_type the above controller will return a 500 error because of the name delegation.
For instance,
Spree::Api::OptionValuesController#create
allows to create an option value record with onlyname
andpresentation
params. Once created, the json response view will call*option_value_attributes
withoption_type_name
breaking the app.This pr also:
check_option_values
from theoption_values_controller_spec.rb
because is not used anywhere in the file.
Checklist: